package fr.umlv.jee.jawp.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.ldap.core.LdapTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import fr.umlv.jee.jawp.persistence.dao.IPersonDAO;
import fr.umlv.jee.jawp.persistence.object.Person;

@Service("personService")
public class PersonService {

	@Resource(name = "personDAO")
	private IPersonDAO dao;

	@Transactional
	public Person createVoidPerson() {
		return new Person();
	}

	@Transactional
	public void setLdapTemplate(LdapTemplate ldapTemplate) {
		dao.setLdapTemplate(ldapTemplate);
	}

	@Transactional
	public boolean create(Person person) {
		// TODO check if exist
		/* CECI EST LA METHODE A UTILISER VIA WEBFLOW ! */
		System.out.println(person);
		dao.create(person);
		return true;
	}

	@Transactional
	public void update(Person person) {
		dao.update(person);
	}

	@Transactional
	public void delete(Person person) {
		dao.delete(person);
	}

	@Transactional
	public Person findByPrimaryKeyMail(String user_id) {
		return dao.findByPrimaryKeyMail(user_id);
	}

	@Transactional
	public List<?> findAll() {
		return dao.findAll();
	}

	@Transactional
	public int getNbPerson() {
		return dao.findAll().size();
	}

	@Transactional
	public List<?> findByName(String name) {
		return dao.findByName(name);
	}

	@Transactional
	public List<?> findByGroup(String group) {
		return dao.findByGroup(group);

	}
}
